﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FXnaWpfBase;

using GWApplication;

namespace GWPresentation
{
    public class TvConceptualModelVM:MDTVIViewModel
    {

        public TvConceptualModelVM(MDTVIViewModel parent,ConceptualModel cm)
            : base(parent)
        {

            this._conceptualModel = cm;


            this._conceptualModel.LayerAdded += new EventHandler(_conceptualModel_LayerAdded);
            this._conceptualModel.LayerRemoved += new EventHandler(_conceptualModel_LayerRemoved);
           


            this.LoadChildren();




 

        }

        void _conceptualModel_LayerRemoved(object sender, EventArgs e)
        {
            TvLayerVM vm = new TvLayerVM(this, sender as TLayer);

            this.Children.Add(vm);

        }

        void _conceptualModel_LayerAdded(object sender, EventArgs e)
        {
            TLayer layer = sender as TLayer;

            TvLayerVM found = null;

            foreach (TvLayerVM item in this.Children)
            {
                if (item.Layer==layer)
                {
                    found = item;
                    
                }
                
            }

            if (found!=null)
            {
                this.Children.Remove(found);
                
            }
           


        }


        ConceptualModel _conceptualModel;

        public ConceptualModel ConceptualModel
        {
            get { return _conceptualModel; }
          
        }


        public override string Desc
        {
            get
            {
                return this._conceptualModel.Desc;
            }
        }


        protected override void LoadChildren()
        {
            base.LoadChildren();

            foreach (TLayer layer in this._conceptualModel.Layers)
            {
                TvLayerVM vm = new TvLayerVM(this,layer);

                this.Children.Add(vm);
                
            }

          
        }



    }
}
